package cn.dnui_lxx432.dnuifood_16110100432.Other;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


import cn.dnui_lxx432.dnuifood_16110100432.JavaBean.ResultBean;
import cn.dnui_lxx432.dnuifood_16110100432.R;
import cn.dnui_lxx432.dnuifood_16110100432.listener.OnRetrofitListener;
import cn.dnui_lxx432.dnuifood_16110100432.model.UserModel;
//import cn.dnui_bsy430.dnuifood_16110100430.R.drawable.me;


public class userUpdate extends AppCompatActivity implements OnRetrofitListener<ResultBean> {
    private TextView username,userpass,phone,address,comment;
    private Button button;
    private ConstraintLayout constraintLayout;
    private String usernames,userpasses,phones,addresses,comments,user_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState);
        setContentView(R.layout.activity_my_details);
        SharedPreferences sharedPreferences = getSharedPreferences("lxx", Context.MODE_PRIVATE);
        String user_id = sharedPreferences.getString("user_id","user_id");
        this.user_id=user_id;
        usernames = getIntent().getStringExtra("username");
        userpasses = getIntent().getStringExtra("userpass");
        phones = getIntent().getStringExtra("phone");
        addresses = getIntent().getStringExtra("address");
        comments = getIntent().getStringExtra("comment");

        initviews();
        initDate();
        inirEvents();

    }
    void inirEvents(){
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getInternet();
            }
        });
    }

    void getInternet(){
        UserModel userModel = new UserModel();
        userModel.updateUserById(user_id,username.getText().toString(),userpass.getText().toString(),phone.getText().toString(),address.getText().toString(),this);
    }
    @Override
    public void onSuccess(ResultBean result, int flag) {
        if (result.getSuccess().equals("1")){
            Toast.makeText(userUpdate.this,"修改成功",Toast.LENGTH_SHORT).show();
            finish();
        }

    }

    @Override
    public void onFailure(String msg) {
        Toast.makeText(userUpdate.this,"网络错误",Toast.LENGTH_SHORT).show();
    }



    void initDate(){
        username.setText(usernames);
        userpass.setText(userpasses);
        phone.setText(phones);
        address.setText(addresses);
        comment.setText(comments);
        button.setText("确认修改");
//        constraintLayout.setBackgroundResource(p3);
    }
    void initviews(){
        username=findViewById(R.id.username1);
        userpass=findViewById(R.id.userpass1);
        phone=findViewById(R.id.phone1);
        address=findViewById(R.id.address1);
        comment=findViewById(R.id.comment1);
        button=findViewById(R.id.signin1);
//        constraintLayout=findViewById(R.id.mydetail_background);
    }
}
